package com.minelx.statementplus.ui.form.dao;

import com.minelx.sqlstructures.statements.clause.Sql;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

public class SqlListModel extends AbstractListModel<Sql> {
	private final List<Sql> elements;

	public SqlListModel() {
		elements = new ArrayList<>();
	}

	public void addElement(Sql content) {
		int index = getSize();
		elements.add(content);
		fireIntervalAdded(this, index, index);
	}

	@Override
	public int getSize() {
		return elements.size();
	}

	@Override
	public Sql getElementAt(int index) {
		return elements.get(index);
	}

	public void removeElement(int index) {
		elements.remove(index);
		fireIntervalRemoved(this, index, index);
	}

	public void clear() {
		int count = getSize();
		elements.clear();
		fireIntervalRemoved(this, 0, count);
	}
}
